'\" te
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2015, Joyent, Inc.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH MEMINFO 2 "Mar 10, 2015"
.SH NAME
meminfo \- provide information about memory
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/mman.h>

\fBint\fR \fBmeminfo\fR(\fBconst uint64_t\fR \fIinaddr\fR[], \fBint\fR \fIaddr_count\fR,
     \fBconst uint_t\fR \fIinfo_req\fR[], \fBint\fR \fIinfo_count\fR, \fBuint64_t\fR \fIoutdata\fR[],
     \fBuint_t\fR \fIvalidity\fR[]);
.fi

.SH PARAMETERS
.ne 2
.na
\fB\fIinaddr\fR\fR
.ad
.RS 14n
array of input addresses; the maximum number of addresses that can be processed
for each call is \fBMAX_MEMINFO_CNT\fR
.RE

.sp
.ne 2
.na
\fB\fIaddr_count\fR\fR
.ad
.RS 14n
number of addresses
.RE

.sp
.ne 2
.na
\fB\fIinfo_req\fR\fR
.ad
.RS 14n
array of types of information requested
.RE

.sp
.ne 2
.na
\fB\fIinfo_count\fR\fR
.ad
.RS 14n
number of pieces of information requested for each address in \fIinaddr\fR
.RE

.sp
.ne 2
.na
\fB\fIoutdata\fR\fR
.ad
.RS 14n
array into which results are placed; array size must be the product of
\fIinfo_count\fR and \fIaddr_count\fR
.RE

.sp
.ne 2
.na
\fB\fIvalidity\fR\fR
.ad
.RS 14n
array of size \fIaddr_count\fR containing bitwise result codes; 0th bit
evaluates validity of corresponding input address, 1st bit validity of response
to first member of \fIinfo_req\fR, and so on
.RE

.SH DESCRIPTION
.LP
The \fBmeminfo()\fR function provides information about virtual and physical
memory particular to the calling process.  The user or developer of performance
utilities can use this information to analyze system memory allocations and
develop a better understanding of the factors affecting application
performance.
.sp
.LP
The caller of \fBmeminfo()\fR can obtain the following types of information
about both virtual and physical memory.
.sp
.ne 2
.na
\fB\fBMEMINFO_VPHYSICAL\fR\fR
.ad
.RS 26n
physical address corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VLGRP\fR\fR
.ad
.RS 26n
locality group of physical page corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VPAGESIZE\fR\fR
.ad
.RS 26n
size of physical page corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPLCNT\fR\fR
.ad
.RS 26n
number of replicated physical pages corresponding to specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPL\fR | \fIn\fR\fR
.ad
.RS 26n
\fIn\fRth physical replica of specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPL_LGRP\fR | \fIn\fR\fR
.ad
.RS 26n
lgrp of \fIn\fRth physical replica of specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_PLGRP\fR\fR
.ad
.RS 26n
locality group of specified physical address
.RE

.sp
.LP
All but \fBMEMINFO_VLGRP\fR and \fBMEMINFO_VPAGESIZE\fR require the
\fBPRIV_PROC_MEMINFO\fR privilege.

.SH RETURN VALUES
.LP
Upon successful completion \fBmeminfo()\fR returns 0. Otherwise \(mi1 is
returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.LP
The \fBmeminfo()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The area pointed to by \fIoutdata\fR or \fIvalidity\fR could not be written, or
the data pointed to by \fIinfo_req\fR or \fIinaddr\fR could not be read.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The value of \fIinfo_count\fR is greater than 31 or less than 1, or the value
of \fIaddr_count\fR is less than 1.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRPrint physical pages and page sizes corresponding to a set of
virtual addresses.
.sp
.LP
The following example prints the physical pages and page sizes corresponding to
a set of virtual addresses.

.sp
.in +2
.nf
void
print_info(void **addrvec, int how_many)
{
    static const uint_t info[] = {
        MEMINFO_VPHYSICAL,
        MEMINFO_VPAGESIZE
    };

    int info_num = sizeof (info) / sizeof (info[0]);
    int i;

    uint64_t *inaddr = alloca(sizeof (uint64_t) * how_many);
    uint64_t *outdata = alloca(sizeof (uint64_t) * how_many * info_num);
    uint_t *validity = alloca(sizeof (uint_t) * how_many);

    for (i = 0; i < how_many; i++)
        inaddr[i] = (uint64_t)addrvec[i];

    if (meminfo(inaddr, how_many, info, info_num, outdata,
                validity) < 0) {
        perror("meminfo");
        return;
    }

    for (i = 0; i < how_many; i++) {
        if ((validity[i] & 1) == 0)
            printf("address 0x%llx not part of address space\en",
                inaddr[i]);

        else if ((validity[i] & 2) == 0)
            printf("address 0x%llx has no physical page "
                "associated with it\en", inaddr[i]);

        else {
            char buff[80];
            if ((validity[i] & 4) == 0)
                strcpy(buff, "<Unknown>");
            else
                sprintf(buff, "%lld",
                    outdata[i * info_num + 1]);

            printf("address 0x%llx is backed by physical "
                "page 0x%llx of size %s\en",
                inaddr[i], outdata[i * info_num], buff);
        }
    }
}
.fi
.in -2

.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Stable
_
MT-Level	Async-Signal-Safe
.TE

.SH SEE ALSO
.LP
.BR memcntl (2),
.BR mmap (2),
.BR gethomelgroup (3C),
.BR getpagesize (3C),
.BR madvise (3C),
.BR sysconf (3C),
.BR attributes (7),
.BR privileges (7)
